/*
 * 地址选择
 */
'use strict';
import React, { Component } from 'react';
import {
    View,
    Text,
    StyleSheet,
    Image,
    ListView,
    RefreshControl,
    ActivityIndicator,
    TouchableOpacity,
    Dimensions,
    Platform,
    Animated,
    PixelRatio,
    TouchableHighlight,
    AsyncStorage,
    Alert,
    ScrollView
} from 'react-native';

import NavTitle from '../component/NavTitle';

import List from 'antd-mobile/lib/list';
import Button from 'antd-mobile/lib/button';

const Item = List.Item;

import Login from './Login';
import Authentication from './Authentication';
import Setting from './Setting';
import ErWeiMaService from './ErweimaService';
import ErweimaShop from './ErweimaShop';
import Deposits from './Deposits';
import EditMyShop from './EditMyShop';
import EditMyService from './EditMyService';


import AddGoods from './AddGoods';
import GoodsDetail from './GoodsDetail';
import ProductShops from './ProductShops';
import ServiceShop from './ServiceShop';
import SpreadGoods from './SpreadGoods';

class Me extends Component {
  constructor(props) {
    super(props)

    this.state = {
        signSta:true,
        userStatus:1
    }
  }

  componentDidMount(){
      this._getLoginStatus();
  }

    _getLoginStatus(){
        AsyncStorage.getItem('serveid').then(value=>{
            if(!value){
                this._login();
            }
        });
    }

    _login(){
        this.props.navigator.push({
            name:'Login',
            component:Login,
        })
    }

    _authentication(){
        AsyncStorage.getItem('serveid').then(value=>{
           if(value){
               this.props.navigator.push({
                   name:'Authentication',
                   component:Authentication
               })
           }else{
               this._login();
           }
        });

    }

    _setting(){
        AsyncStorage.getItem('serveid').then(value=> {
            if(value){
                this.props.navigator.push({
                    name:'Setting',
                    component:Setting
                })
            }else{
                this._login();
            }
        });

    }
    _erweimaService(){
        AsyncStorage.getItem('serveid').then(value=>{
            if(value) {
                this.props.navigator.push({
                    name: 'ErWeiMaService',
                    component: ErWeiMaService,
                    params: {
                        id: value
                    }
                })
            }else{
                this._login();
            }
        })
    }
    _erweimaShop(){
        AsyncStorage.getItem('shopid').then(value=>{
            if(value) {
                this.props.navigator.push({
                    name: 'ErweimaShop',
                    component: ErweimaShop,
                    params: {
                        id: value
                    }
                })
            }else{
                this._login();
            }
        })
    }
    _deposits(){
        AsyncStorage.getItem('serveid').then(value=>{
            if(value){
                this.props.navigator.push({
                    name:'Deposits',
                    component:Deposits
                })
            }else{
                this._login();
            }
        });

    }

    _editMyShop(){
        AsyncStorage.getItem('shopid').then(value=>{
            if(value) {
                this.props.navigator.push({
                    name: 'EditMyShop',
                    component: EditMyShop,
                    params: {
                        id: value
                    }
                })
            }else{
                this._login();
            }
        });
    }

  _editMyService(){
      AsyncStorage.getItem('serveid').then(value=> {
          if (value) {
              this.props.navigator.push({
                  name: 'EditMyService',
                  component: EditMyService,
                  params: {
                      id: value
                  }
              })
          }else {
              this._login();
          }
      })
  }

    _showMyService(){
        AsyncStorage.getItem('serveid').then(value=> {
            if(value) {
                this.props.navigator.push({
                    name: 'ServiceShop',
                    component: ServiceShop,
                    params: {
                        id: value
                    }
                })
            }else{
                this._login();
            }
        })

    }

    _showMyShops(){
        AsyncStorage.getItem('shopid').then(value=>{
            if(value) {
                this.props.navigator.push({
                    name: 'ProductShops',
                    component: ProductShops,
                    params: {
                        id: value,
                        me: true
                    }
                })
            }else{
                this._login();
            }
        });
    }

  render() {
    let logoString = require('../imgs/avatar.png');
    if(this.state.userStatus == 3){
        logoString = require('../imgs/distributor.png');
    }
    if(this.state.userStatus == 2){
        logoString = require('../imgs/Retailer.png');
    }
    return (
      <View style={styles.container}>
        <NavTitle
          title='我'
          headColor = '#fbdc3a'
        />
        <ScrollView
          showsVerticalScrollIndicator={false}
        >
          <List style={styles.bgWhite}>
              <Item arrow="horizontal" onClick={this._showMyService.bind(this)}>
                  <View style={{flexDirection:"row"}}>
                    <Image source={require('../imgs/me1.png')} style={{width:20,height:20}}/>
                    <Text style={{color:'#333',fontSize:14,marginLeft:10}}>我的服务店铺</Text>
                  </View>
              </Item>
              <Item arrow="horizontal" onClick={this._editMyService.bind(this)}>
                  <View style={{flexDirection:"row"}}>
                    <Image source={require('../imgs/me2.png')} style={{width:20,height:20}}/>
                    <Text style={{color:'#333',fontSize:14,marginLeft:10}}>修改我的服务</Text>
                  </View>
              </Item>
              <Item arrow="horizontal" onClick={this._erweimaService.bind(this)}>
                  <View style={{flexDirection:"row"}}>
                      <Image source={require('../imgs/me3.png')} style={{width:20,height:20}}/>
                      <Text style={{color:'#333',fontSize:14,marginLeft:10}}>我的服务二维码</Text>
                  </View>
              </Item>
          </List>
            <List style={styles.bgWhite}>
                <Item arrow="horizontal" onClick={this._showMyShops.bind(this)}>
                    <View style={{flexDirection:"row"}}>
                        <Image source={require('../imgs/me6.png')} style={{width:20,height:20}}/>
                        <Text style={{color:'#333',fontSize:14,marginLeft:10}}>我的产品店铺</Text>
                    </View>
                </Item>
                <Item arrow="horizontal" onClick={this._editMyShop.bind(this)}>
                    <View style={{flexDirection:"row"}}>
                        <Image source={require('../imgs/me7.png')} style={{width:20,height:20}}/>
                        <Text style={{color:'#333',fontSize:14,marginLeft:10}}>修改我的店铺</Text>
                    </View>
                </Item>
                <Item arrow="horizontal" onClick={this._erweimaShop.bind(this)}>
                    <View style={{flexDirection:"row"}}>
                        <Image source={require('../imgs/me3.png')} style={{width:20,height:20}}/>
                        <Text style={{color:'#333',fontSize:14,marginLeft:10}}>我的店铺二维码</Text>
                    </View>
                </Item>
            </List>
            <List style={styles.bgWhite}>
                <Item arrow="horizontal" onClick={this._authentication.bind(this)}>
                    <View style={{flexDirection:"row"}}>
                        <Image source={require('../imgs/me4.png')} style={{width:20,height:20}}/>
                        <Text style={{color:'#333',fontSize:14,marginLeft:10}}>资历认证</Text>
                    </View>
                </Item>
                <Item arrow="horizontal" onClick={this._deposits.bind(this)}>
                    <View style={{flexDirection:"row"}}>
                        <Image source={require('../imgs/me5.png')} style={{width:20,height:20}}/>
                        <Text style={{color:'#333',fontSize:14,marginLeft:10}}>缴纳保证金</Text>
                    </View>
                </Item>
            </List>
            <List style={styles.bgWhite}>
                <Item arrow="horizontal" onClick={this._setting.bind(this)}>
                    <View style={{flexDirection:"row"}}>
                        <Image source={require('../imgs/me8.png')} style={{width:20,height:20}}/>
                        <Text style={{color:'#333',fontSize:14,marginLeft:10}}>设置</Text>
                    </View>
                </Item>
            </List>

        </ScrollView>
      </View>
    )
  }

}

const styles = StyleSheet.create({
    container: {
        backgroundColor: '#EEEEEF',
        flex: 1,
    },
    head:{
        padding:10,
        paddingLeft:15,
        flexDirection:'row',
        backgroundColor:'#F5F5F5',
        borderBottomWidth:1/PixelRatio.get(),
        borderColor:'#E8E8E8',
        marginBottom:10
    },
    bgWhite:{
        marginTop:10
    },
    logo:{
        width:68,
        height:68,
        borderRadius:34
    },
    detail:{
        flex:1,
        height:60,
        alignItems:'flex-start',
        justifyContent: 'center',
        paddingLeft:10
    },
    telphone:{
        color:'#666',
        fontSize:17
    },
    exit:{
        marginTop:20,
        paddingLeft:20,
        paddingRight:20
    }
});

export default Me;
